package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;

public class Main2Activity extends AppCompatActivity {

    private OneFragment oneFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        //动态增加fragment
        //1, 管理者
        FragmentManager manager = getSupportFragmentManager();

        //2,开启事务
        FragmentTransaction fragmentTransaction = manager.beginTransaction();

        //3,增删改
        /**
         * 1,容器id(布局的id)
         * 2,要添加的fragment对象
         */
        oneFragment = new OneFragment();
        fragmentTransaction.add(R.id.ll,oneFragment);
//        BlankFragment blankFragment = new BlankFragment();
//        fragmentTransaction.add(R.id.ll2,blankFragment);
//
//        //替换
//        OneFragment oneFragment1 = new OneFragment();
//        fragmentTransaction.replace(R.id.ll2,oneFragment1);
//
//        //移除
//        fragmentTransaction.remove(oneFragment);
//
//        //隐藏
//        fragmentTransaction.hide(oneFragment1);
//
//        //显示
//        fragmentTransaction.show(oneFragment1);

        fragmentTransaction.commit();

    }

    public void del(View view) {
        //1, 管理者
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.remove(oneFragment);
//        fragmentTransaction.show()
        fragmentTransaction.commit();
    }
}
